//
//  AppDelegate.swift
//  WeiBo_Private
//
//  Created by Yangperlove on 16/1/10.
//  Copyright © 2016年 Yangperlove. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        resignNotification()
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.randomColor()]        
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.backgroundColor = UIColor.whiteColor()
        
        window?.rootViewController = defaultRootController()
//        let nav = UINavigationController(rootViewController: ComposeViewController())
//        window?.rootViewController = nav
//        window?.rootViewController = PictureSelectorViewController()
        
        window?.makeKeyAndVisible()
        
        print(UserAccountViewModel().access_token)
        return true
    }
    
    
    func defaultRootController() -> UIViewController{
        return UserAccountViewModel().isUserLogin() ?  WelcomeViewController() : MainTabBarController() 
    }
    
    //注册成为通知观察者
    func resignNotification() {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "chooseRootController:", name: WeiBoSwitchRootController, object: nil)

    }
    
    func chooseRootController(notification: NSNotification) {
        window?.rootViewController = (notification.object == nil ? MainTabBarController() : WelcomeViewController())
    }

}

